### -*- coding: utf-8 -*- #############################################
# Разработано Паэглит Арвидом (http://arvid.dp.ua/)
# Все права защищены, 2007
#
# Developed by Paeglit Arvid (http://arvid.dp.ua/)
# All right reserved, 2007
#######################################################################

"""Interfaces of user

$Id: interfaces.py 42 2007-12-11 20:00:15Z Arvi3D $
"""
__author__  = "Arvid"
__license__ = "GPL"
__version__ = "$Revision: 42 $"
__date__ = "$Date: 2007-12-11 20:00:15 +0000 (Tue, 11 Dec 2007) $"

from zope.interface import Interface, Attribute, invariant, Invalid
from zope import schema
from zope.interface import implements
from zope.app.container.constraints import contains, containers
from zope.app.container.interfaces import IContained

_ = lambda x : x

class IUserAddForm(Interface):

    auth_id = schema.Int(
                    title = _(u"Identifier")
                    ,description = _(u"Identifier")
                    ,required = True
                    ,readonly = True
                    )

    auth_email = schema.TextLine(
                    title = _(u"Email")
                    ,description = _(u"Email. Unique.")
                    ,required = True
                    )

    auth_name = schema.TextLine(
                    title = _(u"Nickname")
                    ,description = _(u"Nickname. Not unique.")
                    ,required = True
                    )

    auth_password = schema.Password(
                    title = _(u"Password")
                    ,description = _(u"Password")
                    ,required = True
                    )

    passConfirm = schema.Password(
                    title = _(u"Password confirmation")
                    ,description = _(u"Password confirmation")
                    ,required = True
                    )

    @invariant
    def checkPasswordConfirm(user):
        if user.auth_password != user.passConfirm:
            raise Invalid("Wrong password confirmation.")


class IUser(IUserAddForm):
    """The user interface"""

    auth_password = schema.Password(
            title = _(u"Password")
            ,description = _(u"Password")
            ,default = u""
            ,required = False
            )

    passConfirm = schema.Password(
            title = _(u"Password confirmation")
            ,description = _(u"Password confirmation")
            ,default = u""
            ,required = False
            )

    auth_cdate = schema.TextLine(
            title = _(u"Date of construction")
            ,description = _(u"Date and time of construction")
            ,readonly = True
            )

    auth_lastlogin = schema.TextLine(
            title = _(u"Last login")
            ,description = _(u"Date and time of last login")
            ,readonly = True
            )

    auth_istemp = schema.Bool(
            title = _(u"Is temp")
            ,description = _(u"User is temp. This user must to activate account.")
            ,readonly = False
            )

class IUserContained(IContained):
    containers('arvidcontent.principalsource.interfaces.IMountUser')
